package listbyorder.access001_100.test91;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/5 14:30
 */
public class Solution1 {

    // 解码方法
    public int numDecodings(String s) {
        if (s == null || s.equals("")) return 0;
        return getAns(s, 0, s.length());
    }

    private int getAns(String s, int l, int r) {
        if (l == r) return 1;
        if (s.charAt(l) == '0') return 0;
        if (r - l == 1) return 1;
        int n1 = s.charAt(l) - '0';
        int n2 = s.charAt(l + 1) - '0';
        if (n1 * 10 + n2 < 27) {
            return getAns(s, l + 1, r) + getAns(s, l + 2, r);
        } else {
            return getAns(s, l + 1, r);
        }
    }
}
